package cn.lingyangwl.agile.misc.statistic.controller;

import cn.lingyangwl.agile.misc.statistic.model.rqrs.*;
import cn.lingyangwl.agile.misc.statistic.service.*;
import cn.lingyangwl.agile.ram.*;
import cn.lingyangwl.framework.core.response.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 统计登录与登出数据
 * 
 * @author shenguangyang
 */
@Api(tags = "统计登录与登出数据")
@RestController
@RequestMapping("/statistic")
public class StatisticController {
    @Resource
    private StatAnalyzeService analyzeService;
    @Resource
    private StatQueryService queryService;

    @ApiOperation(value = "统计任务")
    @PostMapping("/syncTask")
    public Resp<?> statTask() {
        analyzeService.syncStatistic();
        return Resp.ok();
    }

    @ApiOperation(value = "查询统计访问数据记录")
    @GetMapping("/access/list")
    @RamResource(action = "statistic:access:query", name = "查询统计访问数据", type = ActionType.READ)
    public Resp<List<ChartData>> listAccess(StatBaseReq req) {
        return Resp.ok(queryService.listAccessLog(req));
    }

    @ApiOperation(value = "查询统计统计登录与登出数据")
    @GetMapping("/login/list")
    @RamResource(action = "statistic:login:query", name = "查询统计登录与登出", type = ActionType.READ)
    public Resp<List<ChartData>> listLogin(StatBaseReq req) {
        return Resp.ok(queryService.listLogin(req));
    }
}
